package 多线程.多线程出错解决办法_锁对象;

public class 用户 extends Thread {
    public String name;

    public 用户(String name) {
        this.name = name;
    }
    @Override
    public void run() {
        try {
            银行.lk.lock();
            if (银行.余额 >= 100) {
                银行.余额 -= 100;
                System.out.println(name + "取了100元~~" + "银行还剩" + 银行.余额);
            } else {
                System.out.println("银行的余额不足100元~~");
            }
        } catch (RuntimeException e) {
            throw new RuntimeException(e);
        } finally {
            银行.lk.unlock();
        }
    }
}
